package com.usooft.metaTalent.db.platform.form;

import com.usooft.framework.core.query.Sort;
import com.usooft.framework.web.form.ListForm;
import com.usooft.metaTalent.core.platform.query.ArticleTagQuery;
import java.lang.Boolean;
import java.lang.Long;
import java.lang.Override;
import java.time.LocalDateTime;
import lombok.Setter;

@Setter
public class ArticleTagListForm extends ListForm<ArticleTagQuery> {
    private Long idIs;

    private Long[] idIn;

    private LocalDateTime createdDateOnOrBefore;

    private LocalDateTime createdDateOnOrAfter;

    private Long articleIdIs;

    private Long tagIdIs;

    private Boolean isDeleteIs;

    @Override
    public ArticleTagQuery buildQuery() {
        return ArticleTagQuery.builder()
                                .filter(buildFilter())
                                .sorts(buildSorts())
                                .limit(getLimit())
                                .build();
    }

    private ArticleTagQuery.Filter buildFilter() {
        return ArticleTagQuery.Filter.builder()
                .idIs(idIs)
                .idIn(idIn)
                .createdDateOnOrBefore(createdDateOnOrBefore)
                .createdDateOnOrAfter(createdDateOnOrAfter)
                .articleIdIs(articleIdIs)
                .tagIdIs(tagIdIs)
                .isDeleteIs(isDeleteIs)
                .build();
    }

    private ArticleTagQuery.Sorts buildSorts() {
        ArticleTagQuery.Sorts.Builder builder = ArticleTagQuery.Sorts.builder();
        for (String sortItem : getSortItems()) {
            Sort.Order order = getSortOrder(sortItem);
            switch (sortItem) {
                case "-id", "id" -> builder.id(order);
            }
        }
        return builder.build();
    }
}
